package com.yuyou.train.user.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yuyou.train.service.api.user.dto.UserMedalCategoryDTO;
import com.yuyou.train.service.api.user.entity.UserMedalCategory;
import com.yuyou.train.service.api.user.entity.UserMedalItem;
import com.yuyou.train.user.mapper.UserMedalCategoryMapper;
import com.yuyou.train.user.service.IUserMedalCategoryService;
import com.yuyou.train.user.service.IUserMedalItemService;
import com.yuyou.train.util.bean.Pagination;
import com.yuyou.train.util.bean.ResBoolSimpleInfo;
import com.yuyou.train.util.message.user.UserMedalMess;
import com.yuyou.train.util.tool.Sequence;
import com.yuyou.train.util.tool.UUIDUtil;

@Service
public class UserMedalCategoryServiceImpl implements IUserMedalCategoryService{

	@Autowired
	private UserMedalCategoryMapper userMedalCategoryMapper;

	@Autowired
	private IUserMedalItemService userMedalItemService;
	
	
	@Override
	public int deleteByPrimaryKey(String id) {
		return userMedalCategoryMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(UserMedalCategory record) {
		record.setId(Sequence.getSequence().getNextId());
		record.setCreateTime(new Date());
		record.setIsUse("1");
		return userMedalCategoryMapper.insert(record);
	}

	@Override
	public UserMedalCategoryDTO selectByPrimaryKey(String id) {
		return userMedalCategoryMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(UserMedalCategory record) {
		record.setUpdateTime(new Date());
		return userMedalCategoryMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public ResBoolSimpleInfo deleteMedalCategory(String id) {
		ResBoolSimpleInfo res=new ResBoolSimpleInfo();
		List<UserMedalItem> list=userMedalItemService.findItemBycategoryId(id);
		if(list.size()>0){
			res.setSuccess(false);
			res.setMessage(UserMedalMess.ERR_DEL_MEDAL_ITEM_EXIST);
			return res;
		}
		this.deleteByPrimaryKey(id);
		res.setSuccess(false);		
		return res;
	}

	@Override
	public List<UserMedalCategoryDTO> findMedalCategoryPageList(
			Pagination<UserMedalCategoryDTO> p) {
		return userMedalCategoryMapper.findMedalCategoryPageList(p);
	}

	@Override
	public int findMedalCategoryPageCount(Pagination<UserMedalCategoryDTO> p) {
		return userMedalCategoryMapper.findMedalCategoryPageCount(p);
	}

	@Override
	public List<UserMedalCategory> findUserMedalCategoryList() {
		return userMedalCategoryMapper.findMedalCategoryList();
	}


}